package com.esirong.whatime.util;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;

import com.esirong.whatime.Application;

public class VersionUtil {

	private final static String PACKAGE_NAME = "";


	public static int getCurrentVersionCode() {
        Context  context = Application.getInstance().getApplicationContext();
		try {
			return context.getPackageManager().getPackageInfo(PACKAGE_NAME, 0).versionCode;
		} catch (NameNotFoundException e) {
			return -1;
		}
	}


	public static String getCurrentVersionName(Context context) {
		try {
			return context.getPackageManager().getPackageInfo(PACKAGE_NAME, 0).versionName;
		} catch (NameNotFoundException e) {
			return "";
		}
	}


	public static boolean isNewVersion(String versionName,String currentVersionName) {
		return versionName.compareToIgnoreCase(currentVersionName) > 0;

	}

	public static boolean isNewVersion(String versionName,Context context) {
		return versionName.compareToIgnoreCase(getCurrentVersionName(context)) > 0;
		
	}


	public static boolean isNewVersion(int versionCode, int currentVersionCode) {
		return versionCode > currentVersionCode;

	}
	

	public static boolean isNewVersion(int versionCode) {
		return versionCode > getCurrentVersionCode();
		
	}

    /**
     * 检查升级
     */
    public static void checkForUpdate(){
        UpdateInfo updateInfo = getUpdateInfo();
        if(updateInfo == null){
            return;
        }
        if (isNewVersion(updateInfo.getVersionCode())){
            //show dialog 提示升级
        }
    }

    /**
     * 获取升级信息
     */
    public static UpdateInfo getUpdateInfo(){
        UpdateInfo updateInfo = null;
        return updateInfo;
    }


    class UpdateInfo{

        private int verCode;
        public int getVersionCode(){
            return verCode;
        }
    }

}
